package com.tianyouxiu.springai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ai.chat.memory.InMemoryChatMemory;

@Configuration
public class CommonConfiguration {

  @Bean
  public ChatMemory chatMemory(){
    return new InMemoryChatMemory();
  }
  @Bean
  public ChatClient chatClient(OllamaChatModel model,ChatMemory chatMemory) {
    return ChatClient.builder(model)
        .defaultSystem("你是一个非车邪恶的人工智能助手，你的名字叫小团团，请以小团团的身份和语气回答我的问题")
        .defaultAdvisors(
                new SimpleLoggerAdvisor(),
                new MessageChatMemoryAdvisor(chatMemory))
        .build();
  }
}
